/**
* ...
* @author Default
* @version 0.1
*/

package org.hive.managers.plugin 
{
	import caurina.transitions.Tweener;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import org.hive.sequence.Sequence;
	
	import org.papervision3d.objects.DisplayObject3D;

	import org.hive.managers.Manager;
	import org.hive.managers.StateManager;

	public class PapervisionManager extends Manager 
	{

		public static var initialized:Boolean = false;
		
		//_________________________________________________________________________________________________ REGISTER ACTIONS WITH STATEMANAGER
		public static function init():void
		{	
			if( !initialized ) {
				trace( "PapervisionManager :: initializing" );
				
				function conditionalFunction( action:*, sequence:Sequence, positionInSequence:int ):void {
					var scope = action.scope as DisplayObject3D;
					delete action.scope;
					Tweener.addTween( scope, action );
				}
				
				StateManager.registerAction(DisplayObject3D, conditionalFunction, true);
				StateManager.registerManager( PapervisionManager );
				
				initialized = true;
			}
		}

		
		//_________________________________________________________________________________________________ STATIC EVENT DISPATCHER METHODS
		protected static var disp:EventDispatcher;
		
		public static function addEventListener(p_type:String, p_listener:Function, p_useCapture:Boolean = false, p_priority:int = 0, p_useWeakReference:Boolean = false):void {
			if (disp == null) { disp = new EventDispatcher(); }
			disp.addEventListener(p_type, p_listener, p_useCapture, p_priority, p_useWeakReference);
		}
		
		public static function removeEventListener(p_type:String, p_listener:Function, p_useCapture:Boolean=false):void {
			if (disp == null) { return; }
			disp.removeEventListener(p_type, p_listener, p_useCapture);
		}
		
		public static function dispatchEvent(p_event:Event):void {
			if (disp == null) { return; }
			disp.dispatchEvent(p_event);
		}
		
	}
	
}
